<?php
require_once BACKGROUND_COMMON_ACTION_SERVICE_DIR . '/default.php';

class background_member_reset_password_action_service extends background_default_common_action_service
{
    protected static $_instance;

    public static function get_instance()
    {
        if (null === self::$_instance) {
            self::$_instance = new self();
        }

        return self::$_instance;
    }


    protected function _current_page_process()
    {
        //var_dump(__METHOD__); exit();
                
        $result = array('status' => 0, 'message' => '', 'data' => array());
	     
	    $id = init_user_data_key($_POST, 'id', 'int');
	    //var_dump($id); exit();
	     
	    if(empty($id)){
	        $result['status']  = -6;
	        $result['message'] = '请选择用户';
	    }else{
	        $model_background_member = wwy_resource_container::get_model_background_member();
	        
	        $member_info = $model_background_member->find($id);
	        if(empty($member_info)){
	            $result['status']  = -7;
	            $result['message'] = '该用户不存在';
	        }else{	             
	            $password_no_encode = '123456';
	            $password = md5($password_no_encode);
                $time = time();	                
                $member_info = array(
                    'id'          => $id,
                    'password'    => $password,
                    'update_time' => $time
                );	           	            
	            
	           $update_member_password_result = $model_background_member->update_member_password($member_info);
	           //var_dump($update_member_password_result); exit();
	
                if(!$update_member_password_result){
                    $result['status']  = -9;
                    $result['message'] = '重置密码失败';
                }else{
                    $result['status']  = 1;
                    $result['message'] = '已重置密码为“' . $password_no_encode . '”';
                }
	        }	        
	    }
	    
	    self::set_view_status($result['status']);
	    self::set_view_message($result['message']);
    }
}